import request from "@/service/request";
import {PromisePageResponse, PromiseResponse} from "@/service/api/type.ts";
import {CourseResourceVo, SysUserVo, VodPlayAuth, VodUploadAuth} from "@/service/api/course/resource/types.ts";

/**
 * 私有资源
 * @param query
 */
const getSelfCourseResource = (query: any): PromisePageResponse<CourseResourceVo> => {
  return request({
    url: "/course/resource/self/list",
    method: "get",
    params: query,
  });
};

/**
 * 公共资源
 * @param query
 */
const getPublicCourseResource = (query: any): PromisePageResponse<CourseResourceVo> => {
  return request({
    url: "/course/resource/open/list",
    method: "get",
    params: query,
  });
};

/**
 * 所有资源（管理员）
 * @param query
 */
const getAllCourseResource = (query: any): PromisePageResponse<CourseResourceVo> => {
  return request({
    url: "/course/resource/list",
    method: "get",
    params: query,
  });
};

/**
 * 新建资源，获取上传凭证
 * @param query
 */
const createResource = (query: any): PromiseResponse<VodUploadAuth> => {
  return request({
    url: "/course/resource",
    method: "post",
    data: query,
  });
};

/**
 * 获取用户列表
 * @param query
 */
const getUserList = (query?: any): PromisePageResponse<SysUserVo> => {
  return request({
    url: "/system/user/list",
    method: "get",
    data: query,
  });
};

/**
 * 根据id获取资源详情
 * @param id
 */
const getResourceDetail = (id: string): PromiseResponse<CourseResourceVo> => {
  return request({
    url: `/course/resource/${id}`,
    method: "get",
  });
};

/**
 * 删除资源
 * @param ids
 */
const deleteResource = (ids: string | string[]): PromiseResponse<any> => {
  return request({
    url: `/course/resource/${ids}`,
    method: "delete",
  });
};

/**
 * 编辑资源
 * @param query
 */
const updateResource = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/resource/edit",
    method: "put",
    data: query,
  });
};

/**
 * 获取播放凭证
 * @param id
 */
const getPlayAuth = (id: string): PromiseResponse<VodPlayAuth> =>{
  return request({
    url: `/course/resource/play/${id}`,
    method: "get",
  });
};

export {
  getSelfCourseResource,
  getPublicCourseResource,
  getAllCourseResource,
  createResource,
  getUserList,
  getResourceDetail,
  deleteResource,
  updateResource,
  getPlayAuth
};
